package ajakuulauku;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;

/**
 * Main frame for all graphical things
 * 
 * @author Valdar
 *
 */
@SuppressWarnings("serial")
public class GUI extends JFrame {

	/**
	 * Width of window
	 */
	public static final int WIDTH = 800;
	/**
	 * Height of window
	 */
	public static final int HEIGHT = 600;
	
	/**
	 * Initializes jframe
	 * 
	 * @param container new contentPane
	 */
	GUI() {
		super(GraphicsEnvironment.
				getLocalGraphicsEnvironment().
				getDefaultScreenDevice().
				getDefaultConfiguration());
		//setContentPane(container);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setTitle("Aja kuul auku!!!!!");
		setFocusTraversalKeysEnabled(false);
	}
	
	/**
	 * Prepares and shows jframe
	 */
	public void done() {
		setResizable(false);
		pack();
		getContentPane().setSize(WIDTH, HEIGHT);
		setVisible(true);
	}
	
	/**
	 * Loads image and converts it into BufferedImage
	 * 
	 * @param filename filename of image to load
	 * @return BufferedImage
	 */
	public static BufferedImage loadBufferedImage(String filename) {
		Image img = null;
		try {
			img = ImageIO.read(new File(filename));
		} catch (IOException e) {
			System.out.println("Error loading image" + filename);
		}
		BufferedImage bfimg = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().createCompatibleImage(img.getWidth(null), img.getHeight(null), Transparency.BITMASK);
		bfimg.createGraphics().drawImage(img, 0, 0, new Color (0,0,0,0), null);
		return bfimg;
	}
	
	public static Icon loadIcon(String filename) {
		Image img = null;
		try {
			img = ImageIO.read(new File(filename));
		} catch (IOException e) {
			System.out.println("Error loading image" + filename);
		}
		ImageIcon ico = new ImageIcon(img);
		return ico;
	}
}